#include "UARTDriver.h"


void _uart_begin(int32_t ch, uint32_t b, uint16_t rxS, uint16_t txS);
void _uart_end(int32_t ch);
void _uart_flush(int32_t ch);
bool _uart_is_initialized(int32_t ch);
void _uart_set_blocking_writes(int32_t ch, bool blocking);
bool _uart_tx_pending();

/* Linux implementations of Stream virtual methods */
uint32_t _uart_available(int32_t ch);
uint32_t _uart_txspace(int32_t ch);
int16_t _uart_read(int32_t ch);

/* Linux implementations of Print virtual methods */
size_t _uart_write_char(int32_t ch, uint8_t c);
size_t _uart_write_buffer(int32_t ch, uint8_t *buffer, size_t size);

void _uart_timer_tick(void);

void _uart_begin(int32_t ch, uint32_t b, uint16_t rxS, uint16_t txS){
	uart_begin(ch, b);
}
void _uart_end(int32_t ch){
//	uart_end();
}
void _uart_flush(int32_t ch){
	uart_flush(ch);
}
bool _uart_is_initialized(int32_t ch){
	return 0;//false;
}
void _uart_set_blocking_writes(int32_t ch, bool blocking){
//	uart_set_blocking_writes(blocking);
}
bool _uart_tx_pending(int32_t ch){
	return 0;//uart_tx_pending();
}

/* Linux implementations of Stream virtual methods */
uint32_t _uart_available(int32_t ch){
	return uart_available(ch);
}
uint32_t _uart_txspace(int32_t ch){
	return uart_txspace(ch);
}
int16_t _uart_read(int32_t ch){
    uint8_t buffer = 0;
 	uart_read(ch, &buffer, 1);
	return buffer;
}

/* Linux implementations of Print virtual methods */
size_t _uart_write_char(int32_t ch,uint8_t c){
	uart_write(ch,&c, 1);
	return 1;
}
size_t _uart_write_buffer(int32_t ch, uint8_t *buffer, size_t size){
	return uart_write(ch, buffer, size);
}

void _uart_timer_tick(void){

}

void UARTDriver_constructs(UARTDriver_t *instance){
	instance->available = _uart_available;
	instance->begin = _uart_begin;
	instance->end = _uart_end;
	instance->flush = _uart_flush;
	instance->is_initialized = _uart_is_initialized;
	instance->read = _uart_read;
	instance->set_blocking_writes = _uart_set_blocking_writes;
	instance->timer_tick = _uart_timer_tick;
	instance->tx_pending = _uart_tx_pending;
	instance->txspace = _uart_txspace;
	instance->write = _uart_write_buffer;
	instance->write_byte = _uart_write_char;
}
